<template>
	<view class="conent">
		<!-- <u-navbar :is-back="false" :safeAreaInsetTop="false" height="180rpx">
		</u-navbar> -->
		<view class="conent_box">
			<u-swiper :list="hiveDate.images" imgMode="widthFix" height="690rpx" previousMargin="10" nextMargin="10"
				circular indicator indicatorMode="dot" bgColor="#fff"></u-swiper>
			<u-toast ref="uToast" />
			<view class="introduce">
				<u-row>
					<u-col span="8">
						<u--text :text="hiveDate.hiveName" align="left" size="20" lineHeight="40" bold
							color="#000"></u--text>
						<u--text :text="hiveDate.subtitle" align="left" size="18" lineHeight="40" bold
							color="#333"></u--text>
					</u-col>
					<u-col span="4" customStyle="position: relative;">
						<u-icon name="share" size="34" color="#e5ca8e" @click="sharePoster"
							customStyle="position: absolute;right:0;bottom:30rpx;"></u-icon>
					</u-col>
				</u-row>
				<u-row>
					<u-col span="7">
						<u--text :text="hiveDate.apiaryName" prefixIcon="map-fill"
							iconStyle="font-size:22px;color:#e6ca8d;" align="left" size="16" bold
							color="#000"></u--text>
					</u-col>
					<u-col span="5">
						<u--text :text="hiveDate.price" mode="price" align="right" size="20" lineHeight="40" bold
							color="#FF7643"></u--text>
					</u-col>
				</u-row>
			</view>
			<view class="control">
				<u-grid :border="false" col="4" @click="controlOption">
					<u-grid-item v-for="(item,index) in controlList" :key="index">
						<u--image :src="item.imageUrl" width="55px" height="55px" radius="5"></u--image>
						<u--text :text="item.title" align="center" size="14" :color="index==0?'#07BFA5':'#919191' "
							customStyle="margin-top:10rpx;"></u--text>
					</u-grid-item>
				</u-grid>
				<u-toast ref="uToast" />
			</view>
			<view class="weather">
				<u-row justify="space-between" gutter="12" customStyle="line-height: 50rpx;padding: 20rpx;">
					<u-col span="6">
						<u--text text="蜂场天气信息" bold prefixIcon="eye-fill"
							iconStyle="font-size: 40rpx;color: #e4ca8d;"></u--text>
					</u-col>

					<u-col span="6">
						<u--text text="该天气来源于气象仪" align="right" color="#b7b7b7"></u--text>
					</u-col>
				</u-row>
				<view class="parameterGrid">
					<u-grid :border="false" col="3">
						<u-grid-item v-for="(item,index) in weatherList" :key="index">
							<view class="parameterGridItem">
								<u--text :text="item.title" color="#b7b7b7"></u--text>
								<u--text :text="item.parameter+item.unit" bold lineHeight="60rpx"></u--text>
							</view>
						</u-grid-item>
					</u-grid>
				</view>
				<u-toast ref="uToast" />
			</view>
			<view class="statistics">
				<u-row>
					<u-col span="6">
						<view style="width: 240rpx;height: 240rpx; border-radius: 50%;border: 20rpx solid #07BFA5;">
							<u--image
								src="https://fengfujiafile.oss-cn-hangzhou.aliyuncs.com/adopt/static/page/game.png"
								width="55px" height="55px" radius="5"
								customStyle="margin:auto;margin-top:50rpx"></u--image>
							<u--text text="保底收益" align="center" size="14" color="#2D5150"
								customStyle="margin-top:10rpx;"></u--text>
						</view>
					</u-col>
					<u-col span="6">
						<u-row v-for="(item,index) in earningsList" :key="index">
							<u-col span="6">
								<u--text :text="item.title" align="left" size="12" lineHeight="25"
									color="#6B6B6B"></u--text>
							</u-col>
							<u-col span="6">
								<u--text v-if="index==0" :text="item.parameter" align="left" size="14" bold
									lineHeight="25" color="#2D5140"></u--text>
								<u--text v-else-if="index==1" :text="item.parameter+'/月'" align="left" size="14" bold
									lineHeight="25" color="#2D5140"></u--text>
								<u--text v-else-if="index==5" :text="item.parameter" align="left" size="14" bold
									lineHeight="25" color="#2D5140"></u--text>
								<u--text v-else :text="item.parameter+'KG'" align="left" size="14" bold lineHeight="25"
									color="#2D5140"></u--text>
							</u-col>
						</u-row>
					</u-col>
				</u-row>
				<u-toast ref="uToast" />
			</view>
			<view class="environment">
				<u--image src="https://fengfujiafile.oss-cn-hangzhou.aliyuncs.com/adopt/static/page/userBg.png"
					width="100%" height="200px" radius="20"></u--image>
				<view class="list">
					<view class="offline">
						<u--text text="总体介绍" bold size="20" color="#2D5150" lineHeight="60"
							customStyle="z-index:9;margin-left:20rpx;"></u--text>
						<view
							style="position: absolute;top: 60rpx;left: 30rpx; width: 100rpx;border: 16rpx solid #FFEC45;border-radius: 40rpx 0; background-color: #FFEC45;">
						</view>
						<u-grid border col="2" align="center">
							<u-grid-item bgColor="#EAFFFC"
								customStyle="padding:20rpx 20rpx 80rpx 20rpx; border:20rpx solid #fff;border-radius:30rpx;position:relative;"
								v-for="(item,index) in environmentList" :key="index">
								<view
									style="position: absolute;right: 20rpx;bottom:20rpx; width: 72rpx;height: 72rpx;border-radius: 50%; background: #fff;">
									<u--image :showLoading="true" :src="item.imageUrl" width="18" height="18"
										customStyle="margin:16rpx auto;"></u--image>
								</view>
								<u--text :text="item.title" align="left" size="14" color="#919191"></u--text>
								<u--text v-if="index==0" :text="item.parameter+'°C'" align="left" size="18" bold
									lineHeight="40" color="#07BFA5"></u--text>
								<u--text v-if="index==1" :text="item.parameter+'%'" align="left" size="18" bold
									lineHeight="40" color="#07BFA5"></u--text>
								<u--text v-if="index==2" :text="item.parameter+'只'" align="left" size="18" bold
									lineHeight="40" color="#07BFA5"></u--text>
								<u--text v-if="index==3" :text="item.parameter+'KG'" align="left" size="18" bold
									lineHeight="40" color="#07BFA5"></u--text>
							</u-grid-item>
						</u-grid>
						<u-toast ref="uToast" />
					</view>
					<view class="online">
						<!-- <u--text text="蜜蜂介绍" bold size="20" color="#2D5150" lineHeight="60"
							customStyle="z-index:9;margin-left:20rpx;"></u--text>
						<view
							style="position: absolute;top: 60rpx;left: 30rpx; width: 100rpx;border: 16rpx solid #FFEC45;border-radius: 40rpx 0; background-color: #FFEC45;">
						</view> -->
						<view class="item" v-for="(item,index) in navList" :key="index"
							@click="chooseHoney(item.title,index)">
							<u--text :text="item.title" :bold="index==honeyType" :size="index==honeyType?'20':'14'"
								:color="index==honeyType?'#2D5150':'#747474'" lineHeight="30" align="center"
								customStyle="z-index:9;"></u--text>
							<view v-if="index==honeyType"
								style="position: relative;top:-30rpx; margin:auto; width: 100rpx;border: 16rpx solid #FFEC45;border-radius: 40rpx 0; background-color: #FFEC45;">
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view style="margin-top:500rpx;padding-bottom: 300rpx;">
			<!-- 蜂场详情 -->
			<view v-if="honeyType==0" style="text-align: center;" :style="{maxWidth: maxWidth+'px'}"
				v-html="hiveDate.apiaryIntroduce">
			</view>

			<view v-else class="record">
				<!-- 蜂箱生产记录 -->
				<!-- <u-steps
				current="1" direction="column" activeIcon="checkmark" inactiveIcon="arrow-right">
				<u-steps-item title="已下单" desc="10:30"></u-steps-item>
			</u-steps> -->
				<u-list v-if="hiveDate.breedRecords.length>0">
					<u-list-item v-for="(item, index) in hiveDate.breedRecords" :key="index">
						<view class="item">
							<u--text :text="item.title" bold=""></u--text>
							<u-row justify="space-between" gutter="12"
								customStyle="line-height: 50rpx;padding: 20rpx 0;">
								<u-col span="6">
									<!-- <u-tag :text="item.time" type="warning"></u-tag> -->
									<u--text mode="dateTime" :text="item.time"></u--text>
								</u-col>
								<u-col span="6">
									<u--text :text="'操作人:'+item.operator" bold align="right"></u--text>
								</u-col>
							</u-row>
							<u-read-more showHeight="60" toggle closeText="更多">
								<rich-text :nodes="item.content"></rich-text>
							</u-read-more>
							<u-grid :border="false" v-if="item.image.split(',').length>0">
								<u-grid-item v-for="(baseListItem,baseListIndex) in item.image.split(',')"
									:key="baseListIndex">
									<u--image :src="baseListItem" width="200rpx" height="200rpx"></u--image>
								</u-grid-item>
							</u-grid>
						</view>
					</u-list-item>
				</u-list>
				<u-empty v-else mode="history" text="暂无记录"></u-empty>
			</view>

		</view>
		<u-overlay :show="fosterAddress" :z-index="98" @click="fosterAddress = false"></u-overlay>
		<view v-if="checkedHoney==0" class="flex">
			<u-cell-group v-if="fosterAddress" :border="false">
				<u-cell v-if="addressChoose.id==addressId" title="收货地址"
					:label="addressChoose.name+'&nbsp'+addressChoose.phoneNumber+'\n'+addressChoose.address+'&nbsp'+addressChoose.detailAddress"
					value="更改" isLink @click="alterAddress"></u-cell>
			</u-cell-group>
			<u-row justify="space-between" gutter="12">
				<u-col span="2" customStyle="text-align: center;border-right: 4rpx solid #b7b7b7;">
					<!-- <u-icon name="server-fill" label="客服" labelPos="bottom" size="30" color="#e5ca8e"
						@click="open"></u-icon> -->
					<button type='default' open-type='contact'
						style="border: none;background: #fff;font-size: 12px;padding: 0;">
						<u-icon name="server-fill" size="30" color="#e5ca8e" customStyle="margin:auto;"></u-icon>
						<text style="color: #333;">客服</text>
					</button>
				</u-col>
				<u-col span="1">
				</u-col>
				<u-col span="4">
					<u--text text="认养价:" block align="left"></u--text>
					<u-text mode="price" block align="left" :text="hiveDate.price" size="36rpx" bold lineHeight="60rpx"
						color="#ff0000"></u-text>
				</u-col>
				<u-col span="1">
				</u-col>
				<u-col span="4">
					<u-button v-if="!fosterAddress" text="开始认养" color="#FFB057" @click="adopt"></u-button>
					<u-button v-else text="认养" color="#FFB057" @click="payAdopt"></u-button>
				</u-col>
			</u-row>
		</view>
		<!-- <u-modal :show="serverModalShow" mode="center" confirmText="复制" cancelText="拨号" closeOnClickOverlay
			showCancelButton @confirm="serverModalConfirm" @cancel="serverModalCancel" @close="serverModelClose">
			<view class="popupServer">
				<u--text :text="'客服号码：' + hiveDate.phoneNumber" block align="right"></u--text>
			</view>
		</u-modal> -->
		<u-popup :show="addressPopupShow" mode="center" closeable round="10" @open="addressPopupOpen"
			@close="addressPopupClose">
			<view style="padding:10px">
				<u-row justify="space-between" customStyle="padding:10px 0;">
					<u-col span="5">
						<u-text text="选择收货地址" size="20" bold lineHeight="30" align="left"></u-text>
					</u-col>
					<u-col span="1">
					</u-col>
					<u-col span="5">
						<u-button text="修改地址列表" color="#FFB057" @click="editAddress"></u-button>
					</u-col>
					<u-col span="1">
					</u-col>
				</u-row>
				<u-list height="400px">
					<u-list-item v-for="(item,index) in addressList" :key="index">
						<view class="addressItem" :style="{background:item.defaultFlag?'#8aefe9':''}">
							<u-cell
								:title="item.name+'&nbsp'+item.phoneNumber+'\n'+item.address+'&nbsp'+item.detailAddress"
								:value="item.defaultFlag?'默认':'选择'" :border="false" :name="index"
								@click="chooseAddress"></u-cell>
						</view>
					</u-list-item>
				</u-list>
			</view>
		</u-popup>
		<u-popup :show="sharePopupShow" mode="center" :zoom="false" round="10" @open="sharePopupOpen"
			@close="sharePopupClose">
			<view style="width: 500rpx; padding:10px">
				<u-grid :border="false" col="2">
					<u-grid-item v-for="(item,index) in shareList" :key="index" @click="shareDocument(index)">
						<view v-if="index==0">
							<button type='default' open-type='share'
								style="border: none;background: #fff;font-size: 12px;padding: 0;line-height: 21px;">
								<u--image :showLoading="true" :src="item.imageUrl" width="32px" height="32px"
									radius="50%" customStyle="margin:auto;"></u--image>
								<u--text :text="item.title" align="center" size="12" color="#000"
									customStyle="margin-top:10rpx;"></u--text>
							</button>
						</view>
						<view v-if="index==1"
							style="border: none;background: #fff;font-size: 12px;padding: 0;line-height: 21px;">
							<u--image :showLoading="true" :src="item.imageUrl" width="32px" height="32px" radius="50%"
								customStyle="margin:auto;"></u--image>
							<u--text :text="item.title" align="center" size="12" color="#000"
								customStyle="margin-top:10rpx;"></u--text>
						</view>
					</u-grid-item>
				</u-grid>
			</view>
		</u-popup>
		<u-popup :show="posterPopupShow" mode="center" bgColor="transparent" overlayOpacity="0.8"
			@close="posterPopupClose" @open="posterPopupOpen">
			<view style="width: 540rpx;padding: 20rpx;">
				<u--image :src="poster" width="540rpx" height="840rpx" imgMode="scaleToFill" radius="20rpx"></u--image>
				<u-row justify="space-around" customStyle="position: relative;top:-40rpx;">
					<u-col span="7">
						<u-button color="#e6ca8c" shape="circle" text="保存相册" @click="download"></u-button>
					</u-col>
				</u-row>
			</view>
		</u-popup>
	</view>
</template>

<script setup>
	import {
		ref,
		onMounted
	} from 'vue';
	import router from '@/api/router';
	import {
		onLoad,
		onShow,
		onUnload
	} from "@dcloudio/uni-app";
	import {
		hives,
		shareHive,
		adoptPay
	} from "@/api/pages/hive.js"
	import {
		list
	} from '@/api/pages/address.js'
	const hiveDate = ref({})
	const checkedHoney = ref(0)
	const hiveInfor = ref({})
	const maxWidth = ref('')
	onLoad((options) => {
		console.log("123--", options)
		hiveDate.value = JSON.parse(options.hiveDate)
		checkedHoney.value = JSON.parse(options.checkedHoney)
		console.log("123--", hiveDate.value, checkedHoney.value)
		getHive(hiveDate.value.id)
		uni.getSystemInfo({
			success: res => {
				maxWidth.value = res.windowWidth
				console.log(res.windowWidth);
			}
		})
	})
	const sharePopupShow = ref(false)
	const shareList = ref([{
		imageUrl: "https://fengfujiafile.oss-cn-hangzhou.aliyuncs.com/upload/financialhoneywarehouse/L2A9uaDpqpdY421c7cf3ee12dbe3f0dbd5eda12aa501_1734687237743.png",
		title: "分享给朋友"
	}, {
		imageUrl: "https://fengfujiafile.oss-cn-hangzhou.aliyuncs.com/upload/financialhoneywarehouse/ZsZXb2WQCrgAa7f64932d8bc787472b8251085a3c964_1734687275411.png",
		title: "生成商品图"
	}])
	const poster = ref('')
	const posterPopupShow = ref(false)
	const sharePoster = () => {
		sharePopupShow.value = true
		const pagea = getCurrentPages();
		const path = pagea[pagea.length - 1].route
		const form = {
			page: '',
			scene: hiveDate.value.id
		}
		getShare(form)
	}
	const sharePopupOpen = () => {
		console.log("sharePopupOpen===")
	}
	const sharePopupClose = () => {
		sharePopupShow.value = false
	}
	const getShare = async (form) => {
		const res = await shareHive(form).then()
		poster.value = res.result
	}
	const shareDocument = (index) => {
		if (index == '1') {
			posterPopupShow.value = true
		}
	}
	const onShareAppMessage = (res) => {
		const pagea = getCurrentPages();
		const path = pagea[pagea.length - 1].route
		return {
			title: hiveDate.value.hiveName,
			path: path,
			imageUrl: poster.value,
		}
	}
	const posterPopupOpen = () => {
		console.log("posterPopupOpen===")
	}
	const posterPopupClose = () => {
		posterPopupShow.value = false
	}
	const download = () => {
		console.log("保存到相册===", poster.value);
		uni.getSetting({
			complete(res) {
				console.log(res.authSetting, "授权信息");
				if (res.authSetting['scope.writePhotosAlbum']) {
					console.log(res.authSetting['scope.writePhotosAlbum'], "是否已经授权");
					uni.getImageInfo({
						src: poster.value,
						success(result) {
							console.log(result)
							if (result.path) {
								uni.saveImageToPhotosAlbum({
									filePath: result.path,
								}).then((getImageInfoResult) => {
									if (getImageInfoResult.errMsg ===
										'saveImageToPhotosAlbum:ok') {
										uni.showToast({
											title: "已成功保存至相册！",
											duration: 1000
										})
									} else {
										uni.showToast({
											title: "图片保存失败！",
											duration: 1000
										})
									}
								});
							}
							// uni.saveImageToPhotosAlbum({ //保存图片到系统相册。
							// 	filePath: result.path, //图片文件路径
							// 	success: function() {
							// 		uni.showToast({
							// 			title: '图片保存成功',
							// 			icon: 'none',
							// 		});
							// 	},
							// 	fail: function(e) {
							// 		console.log(e);
							// 		uni.showToast({
							// 			title: '图片保存失败321',
							// 			icon: 'none',
							// 		});
							// 	},
							// });
						}
					})
				} else {
					uni.authorize({
						scope: 'scope.writePhotosAlbum',
					}).then(() => {
						uni.getImageInfo({
							src: poster.value,
							success(result) {
								console.log(result)
								if (result.path) {
									uni.saveImageToPhotosAlbum({
										filePath: result.path,
									}).then((getImageInfoResult) => {
										if (
											getImageInfoResult.errMsg ===
											'saveImageToPhotosAlbum:ok'
										) {
											uni.showToast({
												title: "已成功保存至相册！",
												duration: 1000
											})
										} else {
											uni.showToast({
												title: "图片保存失败！",
												duration: 1000
											})
										}

									})
								}
								// uni.saveImageToPhotosAlbum({ //保存图片到系统相册。
								// 	filePath: result.path, //图片文件路径
								// 	success: function() {
								// 		uni.showToast({
								// 			title: '图片保存成功',
								// 			icon: 'none',
								// 		});
								// 	},
								// 	fail: function(e) {
								// 		console.log(e);
								// 		uni.showToast({
								// 			title: '图片保存失败321',
								// 			icon: 'none',
								// 		});
								// 	},
								// });
							},
						}).catch((err) => {
							console.log(err);
						});

					})
				}
			}
		})
	}
	const hiveCollect = () => {
		hiveDate.value.collect == 1 ? hiveDate.value.collect = 0 : hiveDate.value.collect = 1
	}
	const controlList = ref([{
			imageUrl: "https://fengfujiafile.oss-cn-hangzhou.aliyuncs.com/adopt/static/page/control1.png",
			title: "云台控制",
			url: '/pageA/ezplayer/index'
		},
		{
			imageUrl: "https://fengfujiafile.oss-cn-hangzhou.aliyuncs.com/adopt/static/page/control2.png",
			title: "对讲",
			url: ''
		},
		{
			imageUrl: "https://fengfujiafile.oss-cn-hangzhou.aliyuncs.com/adopt/static/page/control3.png",
			title: "截屏",
			url: ''
		},
		{
			imageUrl: "https://fengfujiafile.oss-cn-hangzhou.aliyuncs.com/adopt/static/page/control4.png",
			title: "回看",
			url: ''
		}
	])
	const controlOption = (name) => {
		console.log("controlOption===", controlList.value[name].title);
		if (controlList.value[name].url == '') {
			uni.showToast({
				title: '服务未开通',
				icon: 'error',
			})
			return
		}
		// <ezplayer
		// 	v-if="hiveDetail.accessToken&&hiveDetail.apiaryMonitorDeviceSerialNo&&hiveDetail.apiaryMonitorChannelNo"
		// 	id="ezplayer" :accessToken="hiveDetail.accessToken"
		// 	:url="'rtmp://open.ys7.com/'+hiveDetail.apiaryMonitorDeviceSerialNo+'/'+hiveDetail.apiaryMonitorChannelNo+'/live'"
		// 	bind:handleError="handleError" />
		if (!hiveDate.value.hiveMonitorDeviceSerialNo || !hiveDate.value.hiveMonitorChannelNo || !hiveDate.value
			.accessToken) {
			uni.showToast({
				title: '设备参数不足,无法查看',
				icon: 'error',
			})
			return
		} else {
			const ezplayerForm = {
				deviceSerial: hiveDate.value.hiveMonitorDeviceSerialNo,
				channelNo: hiveDate.value.hiveMonitorChannelNo,
				accessToken: hiveDate.value.accessToken
			}
			router.navigateTo({
				url: controlList.value[name].url + '?ezplayerForm=' + JSON.stringify(ezplayerForm)
			})
		}
	}
	const earningsList = ref([{
			title: '蜂蜜类型：',
			parameter: ''
		},
		{
			title: '认养周期：',
			parameter: '0'
		},
		{
			title: '蜂蜜：',
			parameter: '0'
		},
		{
			title: '蜂花粉：',
			parameter: '0'
		},
		{
			title: '蜂王浆：',
			parameter: '0'
		},
		{
			title: '权益：',
			parameter: '0'
		}
	])
	const weatherList = ref([{
			title: "温度：",
			unit: '℃',
			parameter: ""
		},
		{
			title: "湿度：",
			unit: '%',
			parameter: ""
		},
		{
			title: "风向：",
			unit: '',
			parameter: ""
		},
		{
			title: "PM2.5：",
			unit: 'μg/m³',
			parameter: ""
		},
		{
			title: "PM10：",
			unit: 'μg/m³',
			parameter: ""
		},
		{
			title: "CO2：",
			unit: 'm³',
			parameter: ""
		}
	])
	const environmentList = ref([{
			imageUrl: "https://fengfujiafile.oss-cn-hangzhou.aliyuncs.com/adopt/static/page/environment1.png",
			title: "当前箱内温度",
			parameter: "0"
		},
		{
			imageUrl: "https://fengfujiafile.oss-cn-hangzhou.aliyuncs.com/adopt/static/page/environment2.png",
			title: "当前箱内湿度",
			parameter: "0"
		},
		{
			imageUrl: "https://fengfujiafile.oss-cn-hangzhou.aliyuncs.com/adopt/static/page/environment3.png",
			title: "今日进出量",
			parameter: "0"
		},
		{
			imageUrl: "https://fengfujiafile.oss-cn-hangzhou.aliyuncs.com/adopt/static/page/environment4.png",
			title: "当前蜂箱重量",
			parameter: "0"
		}
	])
	const navList = ref([{
			title: "蜂场介绍"
		},
		{
			title: "生产记录"
		}
	])
	const honeyType = ref("0") //0蜂场介绍；1生产记录
	const chooseHoney = (title, index) => {
		console.log(title);
		honeyType.value = index
	}
	const quantity = ref("1")
	const quantityChange = (e) => {
		console.log(e);
	}
	const getHive = async (hivesId) => {
		const res = await hives(hivesId).then()
		// hiveInfor.value = res.result
		hiveDate.value = {
			...hiveDate.value,
			...res.result
		}
		earningsList.value = earningsList.value.map((item, index) => {
			switch (index) {
				case 0:
					item.parameter = hiveDate.value.honeyName
					break;
				case 1:
					item.parameter = hiveDate.value.period
					break;
				case 2:
					item.parameter = hiveDate.value.honeyIncome || 0
					break;
				case 3:
					item.parameter = hiveDate.value.beePollenIncome || 0
					break;
				case 4:
					item.parameter = hiveDate.value.royalJellyIncome || 0
					break;
				case 5:
					item.parameter = hiveDate.value.equity || '暂无权益'
					break;
				default:
					item.parameter = '0'
			}
			return item
		})
		weatherList.value = weatherList.value.map((item, index) => {
			switch (index) {
				case 0:
					item.parameter = hiveDate.value.apiaryTemperature || 0
					break;
				case 1:
					item.parameter = hiveDate.value.apiaryHumidity || 0
					break;
				case 2:
					item.parameter = hiveDate.value.apiaryWindDirection || 0
					break;
				case 3:
					item.parameter = hiveDate.value.apiaryPM25 || 0
					break;
				case 4:
					item.parameter = hiveDate.value.apiaryPM10 || 0
					break;
				case 5:
					item.parameter = hiveDate.value.apiaryCO || 0
					break;
				default:
					item.parameter = '0'
			}
			return item
		})
		environmentList.value = environmentList.value.map((item, index) => {
			switch (index) {
				case 0:
					item.parameter = hiveDate.value.hiveTemperature || 0
					break;
				case 1:
					item.parameter = hiveDate.value.hiveHumidity || 0
					break;
				case 2:
					item.parameter = hiveDate.value.quantity || 0
					break;
				case 3:
					item.parameter = hiveDate.value.weight || 0
					break;
				default:
					item.parameter = '0'
			}
			return item
		})
		console.log(hiveDate.value, earningsList.value);
		// = hiveDate.value.honeyName
	}
	// const serverModalShow = ref(false)
	// const open = () => {
	// 	console.log("打开客服===");
	// 	serverModalShow.value = true
	// }
	// const serverModalConfirm = () => {
	// 	uni.setClipboardData({
	// 		data: hiveDate.value.phoneNumber, //text是要复制的文本
	// 		success: function(res) {
	// 			uni.getClipboardData({
	// 				//这个api是把拿到的数据放到剪切板中的
	// 				success: function(res) {
	// 					uni.showToast({
	// 						title: '复制成功',
	// 						icon: "none",
	// 					})
	// 					serverModelClose()
	// 				}
	// 			})
	// 		}
	// 	})
	// }
	// const serverModalCancel = () => {
	// 	uni.makePhoneCall({
	// 		phoneNumber: hiveDate.value.phoneNumber
	// 	})
	// }
	// const serverModelClose = () => {
	// 	serverModalShow.value = false
	// }
	const addressPopupShow = ref(false)
	const fosterAddress = ref(false)
	const addressList = ref([])
	const addressNumber = ref(0)
	const addressChoose = ref({})
	const addressId = ref('')
	const adopt = () => {
		console.log("开始认养===")
		getAddressList({
			pageNo: 1,
			pageSize: 99
		})
	}
	const payAdopt = () => {
		const payForm = {
			hiveId: hiveDate.value.id,
			addressId: addressId.value
		}
		console.log("认养===", payForm)
		getAdoptPay(payForm)
	}
	const getAdoptPay = async (form) => {
		const res = await adoptPay(form)
		console.log("res---", res);
		if (res.code == 200) {
			uni.requestPayment({
				provider: 'wxpay', // 服务提提供商
				appId: res.result.appId,
				timeStamp: JSON.stringify(res.result.timeStamp), // 时间戳
				nonceStr: res.result.nonceStr, // 随机字符串
				package: res.result.prepayId,
				signType: 'SHA256withRSA', // 签名算法
				paySign: res.result.sign, // 签名
				success: function(res) {
					console.log('支付成功', res);
					uni.showToast({
						title: '认养成功',
						icon: 'success',
					})
					// 业务逻辑。。。
					router.reLaunch({
						url: '/pages/index/index',
					})
				},
				fail: function(err) {
					console.log('支付失败', err);
				}
			})
		}
	}
	const addressPopupOpen = () => {
		console.log("addressPopupOpen===")
	}
	const addressPopupClose = () => {
		addressPopupShow.value = false
	}
	const getAddressList = async (form) => {
		const res = await list(form)
		console.log("res---", res);
		if (res.result.total == 0) {
			uni.showModal({
				title: '提示',
				content: '地址列表为空，需要添加有效地址',
				success: function(res) {
					if (res.confirm) {
						router.navigateTo({
							url: "/pageD/feature/address"
						})
						// console.log('确认');
					} else if (res.cancel) {
						console.log('取消');
					}
				}
			})
		} else {
			addressList.value = res.result.records
			addressChoose.value = res.result.records[addressNumber.value]
			addressId.value = res.result.records[addressNumber.value].id
			fosterAddress.value = true
			// addressPopupShow.value = true
		}
	}
	const chooseAddress = (name) => {
		addressNumber.value = name.name
		addressChoose.value = addressList.value[name.name]
		addressId.value = addressList.value[name.name].id
		console.log("chooseAddress===", addressChoose.value.id, name.name, addressNumber.value, addressList.value[
			addressNumber.value].id, addressList.value[name
			.name].id, addressId.value);
		addressPopupClose()
	}
	const offAddress = () => {
		fosterAddress.value = false
	}
	const alterAddress = () => {
		addressPopupShow.value = true
	}
	const editAddress = () => {
		router.navigateTo({
			url: "/pageD/feature/address"
		})
	}
</script>

<style scoped lang="scss">
	:deep(.u-navbar__content__left) {
		display: none;
	}

	:deep(.u-border-bottom),
	:deep(.u-border-right) {
		border-color: #fff !important;
	}

	uni-button:after,
	button::after {
		border: none;
	}

	.conent_box {
		margin-top: 0;
		padding: 0 10rpx;
		// padding-bottom: 100rpx;

		.introduce,
		.statistics,
		.weather {
			margin-top: 20rpx;
			padding: 30rpx;
			border-radius: 20rpx;
			box-shadow: 2px 2px 2px rgba(0, 0, 0, .3);
			background: #fff;
			position: relative;

			.collect {
				position: absolute;
				top: 100rpx;
				right: 0;
				width: 80rpx;
				height: 80rpx;
				padding: 10rpx 35rpx;
				background: #F5F6F9;
				border-radius: 100rpx 0 0 100rpx;
				text-align: center;
				line-height: 100rpx;
			}
		}

		.control {
			margin-top: 40rpx;
		}

		.environment {
			margin-top: 20rpx;
			position: relative;

			.list {
				width: 84%;
				padding: 20rpx 4%;
				position: absolute;
				top: 150rpx;
				left: 4%;
				border-radius: 20rpx;
				box-shadow: 2px 2px 2px rgba(0, 0, 0, .3);
				background: #fff;


				.offline,
				.online {
					position: relative;
				}

				.online {
					// position: relative;
					display: flex;
					justify-content: space-around;

					.item {
						margin-right: 20rpx;
						position: relative;
						flex: 1;
						// display: flex;
						// padding: 20rpx 40rpx;
					}
				}
			}
		}
	}

	// .introduce,
	.record {
		padding: 20rpx;
		// .beeVideo {
		// 	width: 100%;
		// 	height: 300rpx;
		// 	border-radius: 10rpx;

		// 	video {
		// 		width: 100%;
		// 		height: 300rpx;
		// 		border-radius: 10rpx;
		// 	}
		// }
		.item {
			padding: 20rpx;
			margin-bottom: 20rpx;
			border-radius: 10rpx;
			border: 2rpx solid #d5d5d5;
			box-shadow: 2rpx 2rpx 1rpx 2rpx #d5d5d5;
		}
	}


	.flex {
		position: fixed;
		bottom: 0;
		width: 90%;
		padding: 20rpx 5%;
		background: #fff;
		z-index: 99;
	}

	.addressItem {
		margin: 10rpx;
		padding: 10rpx;
		background-color: #fff;
		box-shadow: 2px 2px 2px rgba(0, 0, 0, .3);
		border-radius: 20rpx;
	}

	.parameter {
		position: fixed;
		bottom: 0;
		width: 90%;
		padding: 20rpx 5%;
		background: #fff;
		border-radius: 40rpx 40rpx 0 0;
		z-index: 10;

		.specification {
			padding-top: 20rpx;

			.kind {
				padding: 20rpx 0;
				display: flex;
				flex-wrap: wrap;
				justify-content: flex-start;

				>view {
					font-size: 24rpx;
					padding: 10rpx 30rpx;
					margin: 10rpx;
					border-radius: 44rpx;
				}
			}
		}
	}
</style>